<html lang="zh">
<meta charset="UTF-8">
<!--<meta name="viewport" content="width=device-width,initial-scale=1">-->
<script src="./js/vue.js" type="text/javascript"></script>
<script src="./js/axios.min.js" type="text/javascript"></script>
<script src="./js/api.js" type="text/javascript"></script>
<script src="./js/element-ui.js" type="text/javascript"></script>
<link href="./css/element-ui.css" type="text/css" rel="stylesheet">
<script src="./js/crypto-js.js" type="text/javascript"></script>
<script src="./js/sm2.js" type="text/javascript"></script>
<link href="./css/default.css" type="text/css" rel="stylesheet">
<script src="./js/default.js" type="text/javascript"></script>
<body>
<div id="app">
    <el-container style="height: 100%" v-if="!complete">
        <!--        <el-container style="height: 100%">-->
        <el-aside width="500px">
            <div style="height: calc(100% - 125px);position: relative">
                <img class="center" :src="'data:png/image;base64,'+tpBase64">
            </div>
            <div>
                <el-form size="mini" label-width="120px">
                    <el-form-item label="走查项目">
                        <div style="display: inline-block;width: calc((100% - 200px) / 2);" class="text">
                            {{gcmc}}
                        </div>
                        <div style=" display: inline-block;margin-left: 50px;vertical-align: top">
                            评审模式
                            <el-checkbox size="mini" v-model="sfpsms"
                                         style="vertical-align: top;margin-top: 7px;margin-left: 10px"></el-checkbox>
                        </div>
                    </el-form-item>
                    <el-form-item label="开发人员" v-if="!sfpsms">
                        <el-select size="mini" v-model="kfry" value-key="rybm" style="width: 270px;">
                            <el-option v-for="item in ryList" :key="item.rybm" :value="item"
                                       :label="item.rymc"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="评审计划编号" v-if="sfpsms">
                        <el-input v-model="psjhbh" style="width: 270px;"></el-input>
                    </el-form-item>
                    <el-form-item label="走查文件">
                        <div :title="zcywjbh" class="text">{{zcywjbh}}</div>
                    </el-form-item>
                </el-form>
            </div>
        </el-aside>
        <el-main>
            <div style="width: 100%;height:30px;overflow:hidden;">
                <span>检索</span>
                <el-input style="display: inline-block;max-width: 300px;width: unset;" size="mini"
                          v-model="psbzStr"></el-input>
            </div>
            <div style="height:calc( 100% - 30px)">
                <el-table :data="zcbzList" height="100%" size="mini" row-key="psbzbm" style="min-width: 700px;"
                          :row-class-name="rowClass">
                    <el-table-column prop="xh" width="80px" label="序号"></el-table-column>
                    <el-table-column prop="mc" label="标准名称">
                        <template scope="{row}">
                            <div v-html="highlight(row.mc)"></div>
                        </template>
                    </el-table-column>
                    <el-table-column label="评审意见">
                        <template scope="{row}">
                            <el-input size="mini" v-model="row.psnr" v-if="row.sfkbj"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column label="意见等级">
                        <template scope="{row}">
                            <el-select size="mini" v-model="row.yjdj" v-if="row.sfkbj" clearable>
                                <el-option v-for="i in 3" :label="i" :value="i" :key="i">{{i}}</el-option>
                            </el-select>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </el-main>
        <!--        </el-container>-->
        <!--        <el-footer style="border-top: 1px solid #ccc">-->
        <!--            <div style="height: 100%;text-align: right;">-->
        <!--                <el-button type="primary" style="margin-top: 20px" size="mini" @click="addDmzc">提交</el-button>-->
        <!--            </div>-->
        <!--        </el-footer>-->
    </el-container>
    <div v-else style="text-align: center;padding-top: 20px">
        <h1>请点击右上角关闭</h1>
    </div>
</div>
</body>
<script type="text/javascript">

  let vue = new Vue({
    el: '#app',
    data() {
      return {
        complete: false,
        zcbzList: [],
        ryList: [],
        sfpsms: false,
        kfry: {rybm: ''},
        gcmc: "",
        xmlx: "",
        tpBase64: "",
        psjhbh: '',
        zcywjbh: '',
        psbzStr: '',
      };
    },
    created() {
    },
    mounted() {
      this.queryPsbzfllb()
      this.queryRylb()
      this.getGcxx()
    },
    methods: {
      highlight(str) {
        if (!this.psbzStr) {
          return str
        }
        let reg = new RegExp(this.psbzStr, "g")
        return str.replace(reg, w => {
          return "<span style=\"color:white;background-color: red\">" + w + "</span>"
        })
      },
      async getGcxx() {
        let res = await this.$api.getGcxx({
          gcmc: getQueryString("gcmc")
        })
        this.gcmc = res.gcmc
        this.xmlx = res.xmlx
        this.tpBase64 = res.tpBase64
        this.zcywjbh = res.zcywjbh


        this.kfry = myLocalStorage.getItem("lastKfry-" + this.gcmc, {rybm: ''});
        this.sfpsms = myLocalStorage.getItem("sfpsms-" + this.gcmc, false)
        this.psjhbh = myLocalStorage.getItem("psjhbh-" + this.gcmc, '')
      },
      async addDmzc() {
        if (this.complete) {
          this.$message.error(`请勿重复提交`)
          return
        }
        myLocalStorage.setItem("lastKfry-" + this.gcmc, this.kfry)
        myLocalStorage.setItem("sfpsms-" + this.gcmc, this.sfpsms)
        myLocalStorage.setItem("psjhbh-" + this.gcmc, this.psjhbh)

        let obj = {
          gcmc: this.gcmc,
          jtwj: this.tpBase64,
          bz: this.bz,
          zcywjbh: this.zcywjbh,
          zcqks: [],
          xmlx: this.xmlx
        }
        for (let zcbzListElement of this.zcbzList) {
          if (!zcbzListElement.psnr || !zcbzListElement.sfkbj) {
            continue
          }
          if (!zcbzListElement.yjdj) {
            throw new Error("请填录意见等级！");
          }
          if (this.sfpsms) {
            obj.zcqks.push({
              yjdj: zcbzListElement.yjdj,
              zcyj: zcbzListElement.psnr,
              psbzbm: zcbzListElement.psbzbm
            })
          } else {
            obj.zcqks.push({
              yjdj: zcbzListElement.yjdj,
              zcyj: zcbzListElement.psnr,
              psbzbm: zcbzListElement.psbzbm,
              kfrybm: this.kfry.rybm,
              kfrymc: this.kfry.rymc
            })
          }
        }
        try {
          if (obj.zcqks.length === 0) {
            throw new Error("评审意见不能全部为空");
          }
          let res;
          if (this.sfpsms) {
            if (!this.psjhbh) {
              throw new Error("评审计划编号不能为空")
            }
            obj.psjhbh = this.psjhbh
            res = await this.$api.addJhdmzc(obj)
          } else {
            if (!this.kfry.rybm) {
              throw new Error("开发人员不能为空")
            }
            res = await this.$api.addDmzc(obj)
          }
          this.$message.success("走查成功")

          this.complete = true
          window.close()
        } catch (e) {
          console.error(e)
          this.$message.error(`走查失败：${e.message}`)
        }
      },
      async queryRylb() {
        let res = await this.$api.queryRylb({
          pageNum: 1,
          pageSize: 9999,
          filter: {}
        })
        this.ryList = res.list;
      },
      async queryPsbzfllb() {
        let res = await this.$api.queryPsbzfllb({
          pslxbm: "534FF7DDC2B04EFBBC8EDA348F6B07F5"
        })
        let i = 0
        for (const re of res) {
          if (re.psbzflbm === 'BFFA39FF65E0408984708C789679818E' || re.psbzflmc === '前端规范') {
            continue
          }
          if (re.psbzflbm === '844D246A5B4F4D09ABAE3FBB944FAC7E' || re.psbzflmc === '单元测试') {
            continue
          }
          i++;
          this.zcbzList.push({
            xh: i,
            sfkbj: false,
            mc: re.psbzflmc,
            psnr: null,
            yjdj: null
          })
          let r = await this.$api.queryPsbzlb({
            pageNum: 1,
            pageSize: 99999,
            filter: {
              pslxbm: "534FF7DDC2B04EFBBC8EDA348F6B07F5",
              psbzflbm: re.psbzflbm
            }
          })
          for (let j = 0; j < r.list.length; j++) {
            const listElement = r.list[j]
            this.zcbzList.push({
              xh: `${i}.${j + 1}`,
              sfkbj: true,
              psbzbm: listElement.psbzbm,
              mc: listElement.jcnr,
              psnr: null,
              yjdj: null
            })
          }
        }
      },
      rowClass({row}) {
        return row.sfkbj ? '' : 'rowtitle'
      }
    }
  });

  function submit() {
    vue.addDmzc()
  }
</script>
</html>
